package qc.module.ehs.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.ehs.dto.epibolyunit.EpibolyUnitDto;
import qc.module.ehs.dto.epibolyunit.EpibolyUnitQueryConditionDto;
import qc.module.ehs.service.EhsEpibolyUnitService;

import java.util.List;

/**
 * EpibolyUnitController
 * @author YRR
 * @create 2025-03-13 10:04
 */
@RestController
@RequestMapping("/epibolyunit")
public class EpibolyUnitController {

    @Autowired
    private EhsEpibolyUnitService service;

    /**
     * 查询相关方单位
     * @param dto 查询条件
     * @return List<EpibolyUnitDto>
     * @throws QCPromptException
     */
    @RequestMapping(value = "/query", method = {RequestMethod.POST, RequestMethod.GET})
    public List<EpibolyUnitDto> query(@RequestBody EpibolyUnitQueryConditionDto dto) throws QCPromptException {
        return service.query(dto);
    }

    /**
     * 新增相关方单位
     * @param dto 相关方单位信息
     * @return String
     */
    @RequestMapping(value = "/add", method = {RequestMethod.POST, RequestMethod.PUT})
    public String add(@RequestBody EpibolyUnitDto dto) {
        return service.add(dto);
    }

    /**
     * 修改相关方单位,通过dto
     * @param dto 相关方单位信息
     * @return
     */
    @RequestMapping(value = "/update", method = {RequestMethod.PUT, RequestMethod.POST})
    public String update(@RequestBody EpibolyUnitDto dto) {
        return service.update(dto);
    }

    /**
     * 修改指定相关方单位的状态，设置为黑名单
     * @param id 相关方单位id
     * @return 返回null表示成功，错误返回提示信息
     */
    @RequestMapping(value = "/blacklist", method = {RequestMethod.POST, RequestMethod.PUT})
    public String addToBlackListByParam(@RequestParam(value = "id", required = true) String id) {
        return service.addToBlackList(id);
    }

    /**
     * 修改指定相关方单位的状态，设置为黑名单
     * @param id 相关方单位id
     * @return 返回null表示成功，错误返回提示信息
     */
    @RequestMapping(value = "/blacklist/{id}", method = {RequestMethod.POST, RequestMethod.PUT})
    public String addToBlackListByPath(@PathVariable(value = "id", required = true) String id) {
        return service.addToBlackList(id);
    }

    /**
     * 删除指定的相关方单位
     * @param id 相关方单位id
     * @return null表示成功，错误返回提示信息
     */
    @DeleteMapping("/delete")
    public String deleteByParam(@RequestParam(value = "id", required = true) String id) {
        return service.delete(id);
    }

    /**
     * 删除指定的相关方单位
     * @param id 相关方单位id
     * @return null表示成功，错误返回提示信息
     */
    @DeleteMapping("/delete/{id}")
    public String deleteByPath(@PathVariable(value = "id", required = true) String id) {
        return service.delete(id);
    }

}
